package com.study.designmodes.service.liabilityChain.v5.handler;

import com.study.designmodes.service.liabilityChain.v5.OrderDetailVO;
import com.study.designmodes.service.liabilityChain.v5.OrderHandleContext;
import com.study.designmodes.service.liabilityChain.v5.OrderHandlerWeightEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * vip订单处理程序
 *
 * @author yangyanbin
 * @date 2023/06/13
 * @since 20230613
 */
@Slf4j
@Component("VipOrderHandler")
public class VipOrderHandler implements OrderHandler {
    /**
     * 具体处理类
     *
     * @param context 包括原始查询值 和 处理结果 等
     */
    @Override
    public <T extends OrderDetailVO> void handle(OrderHandleContext context) {
        if (context.getRequestParam().getVipLevel() > 2) {
            context.setDetailVO(context.getDetailVO().setFianlPrice(context.getDetailVO().getFianlPrice() - 6));
            log.info("满足会员等级扣减后的价格{}", context.getDetailVO().getFianlPrice());
        }

    }

    /**
     * 处理类权重
     *
     * @return {@link Double}
     */
    @Override
    public Integer weight() {
        return OrderHandlerWeightEnum.VIP.getCode();
    }
}
